<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/3/31
 * Time: 9:58
 */

namespace Caoyong\Tests;

class HelperTest extends \PHPUnit_Framework_TestCase
{
    public function testXML()
    {
        $data = [
            'articles' => [
                'item' => [
                    [
                        'id' => 1,
                        'title' => 'article1'
                    ],
                    [
                        'id' => 2,
                        'title' => 'article2'
                    ]
                ]
            ]
        ];
        $original = '<xml><articles><item><id>1</id><title><![CDATA[article1]]></title></item><item><id>2</id><title><![CDATA[article2]]></title></item></articles></xml>';
        $xml = simplexml_load_string($original);
        $this->assertEquals(dataToXML($data, 'xml'), $xml->asXML());
    }

    public function testAarrayInspector()
    {
        $index_array = [1,2,3,4];
        $assoc_array = ['a' => 1,'b' => 2];
        $mixed_array = [1,'a' => 1];

        $this->assertTrue(isIndexArray($index_array));
        $this->assertFalse(isIndexArray($assoc_array));

        $this->assertTrue(isAssocArray($assoc_array));
        $this->assertFalse(isAssocArray($index_array));

        $this->assertFalse(isIndexArray($mixed_array));
        $this->assertFalse(isAssocArray($mixed_array));
    }
}
